import { getQueryObject, param } from '@/utils/searchParam'
import { nextTick } from 'vue'
import { setToken } from "@/utils/auth";

function microRedirect() {
	const url = location.href.split('?')[0]
	const urlSearch: any = getQueryObject(location.href)
	if (Object.keys(urlSearch).length) {
		if (urlSearch.token) {
			const token = urlSearch.token
			setToken(token)
			delete urlSearch.token
			if (Object.keys(urlSearch).length) {
				nextTick(() => {
					window.history.replaceState('', '', param(urlSearch))
				})
			} else {
				nextTick(() => {
					window.history.replaceState('', '', '')
				})
			}
		}
	}
}
microRedirect()
